﻿using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

using Telerik.WinControls.UI;
using Telerik.WinControls;

using LIM.forms;
using System.Reflection;
using System.Threading;

namespace LIM
{
    class CreateMenuItemInRibbonBar
    {
        RadRibbonBar radRibbonBar;
        Main mainForm;
        string path = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

        public CreateMenuItemInRibbonBar(RadRibbonBar radRibbonBar)
        {
            this.radRibbonBar = radRibbonBar;
            this.radRibbonBar.StartMenuBottomStrip.Clear();
            this.mainForm = (Main)this.radRibbonBar.Parent;
        }

        public void CreateStartMenuItems()
        {
            radRibbonBar.StartMenuItems.Add(CreateMenuItem("Thông tin cá nhân", "radMenuItem_ThongTinCaNhan", @"\icons\icons-32\green\User.png"));
            radRibbonBar.StartMenuItems.Add(CreateMenuItem("Thay đổi mật khẩu", "radMenuItem_ThayDoiMatKhau", @"\icons\icons-32\green\Login2.png"));
            radRibbonBar.StartMenuItems.Add(new RadMenuSeparatorItem());
            
            // Danh mục hệ thống
            RadMenuItem radMenuItem_DanhMuc = CreateMenuItem("Danh mục", "radMenuItem_DanhMucHeThong", @"\icons\icons-32\blue\Merge Rows.png");
            radRibbonBar.StartMenuItems.Add(radMenuItem_DanhMuc);
            // Danh mục Phòng Ban
            RadMenuItem radMenuItem_DanhMucPhongBan = CreateMenuItem("Danh mục Phòng Ban", "radMenuItem_DanhMucPhongBan", @"\icons\icons-32\gray\Merge Rows.png");
            radMenuItem_DanhMuc.Items.Add(radMenuItem_DanhMucPhongBan);
            radMenuItem_DanhMucPhongBan.Click += new EventHandler(radMenuItem_DanhMucPhongBan_Click);
            // Phân cách
            radMenuItem_DanhMuc.Items.Add(new RadMenuSeparatorItem()); 
            // Danh mục chỉ tiêu
            RadMenuItem radMenuItem_DanhMucChiTieu = CreateMenuItem("Danh mục Chỉ tiêu", "radMenuItem_DanhMucChiTieu", @"\icons\icons-32\blue\Merge Rows.png");
            radMenuItem_DanhMuc.Items.Add(radMenuItem_DanhMucChiTieu);
            radMenuItem_DanhMucChiTieu.Click += new EventHandler(radMenuItem_DanhMucChiTieu_Click);
            // Danh mục loại chỉ tiêu
            RadMenuItem radMenuItem_DanhMucLoaiChiTieu = CreateMenuItem("Danh mục Loại Mẫu", "radMenuItem_DanhMucLoaiChiTieu", @"\icons\icons-32\orange\Merge Rows.png");
            radMenuItem_DanhMuc.Items.Add(radMenuItem_DanhMucLoaiChiTieu);
            radMenuItem_DanhMucLoaiChiTieu.Click += new EventHandler(radMenuItem_DanhMucLoaiChiTieu_Click);
            // Danh mục hệ thống
            RadMenuItem radMenuItem_DanhMucHeThong = CreateMenuItem("Danh mục Hệ thống", "radMenuItem_DanhMucHeThong", @"\icons\icons-32\black\Merge Rows.png");
            radMenuItem_DanhMuc.Items.Add(radMenuItem_DanhMucHeThong);
            radMenuItem_DanhMucHeThong.Click += new EventHandler(radMenuItem_DanhMucHeThong_Click);
                        
            radRibbonBar.StartMenuItems.Add(new RadMenuSeparatorItem());

            // Quản trị người dùng
            RadMenuItem radMenuItem_QuanTriNguoiDung = CreateMenuItem("Quản trị người dùng", "radMenuItem_QuanTriNguoiDung", @"\icons\icons-32\orange\User-Monitor.png");
            radRibbonBar.StartMenuItems.Add(radMenuItem_QuanTriNguoiDung);
            radMenuItem_QuanTriNguoiDung.Click += new EventHandler(radMenuItem_QuanTriNguoiDung_Click);

            // Phân quyền hệ thống
            RadMenuItem radMenuItem_PhanQuyenHeThong = CreateMenuItem("Phân quyền hệ thống", "radMenuItem_PhanQuyenHeThong", @"\icons\icons-32\gray\User-Monitor.png");
            radRibbonBar.StartMenuItems.Add(radMenuItem_PhanQuyenHeThong);
            radMenuItem_PhanQuyenHeThong.Click += new EventHandler(radMenuItem_PhanQuyenHeThong_Click);
            
            //radRibbonBar.StartMenuItems.Add(CreateMenuItem("Quản trị người dùng", "radMenuItem_QuanTriNguoiDung", @"\icons\icons-32\orange\User-Monitor.png"));
            //RadMenuItem radMenuItem_CauHinhKetNoi = CreateMenuItem("Cấu hình kết nối", "radMenuItem_CauHinhKetNoi", @"\icons\icons-32\orange\Tools.png");
            //radRibbonBar.StartMenuItems.Add(radMenuItem_CauHinhKetNoi);
            //radMenuItem_CauHinhKetNoi.Click += new EventHandler(radMenuItem_CauHinhKetNoi_Click);

            radRibbonBar.StartMenuItems.Add(new RadMenuSeparatorItem());            
            RadMenuItem radMenuItem_DangXuat = CreateMenuItem("Đăng xuất", "radMenuItem_DangXuat", @"\icons\icons-32\gray\Logout.png");
            radRibbonBar.StartMenuItems.Add(radMenuItem_DangXuat);
            radMenuItem_DangXuat.Click += new EventHandler(radMenuItem_DangXuat_Click);
        }

        void radMenuItem_DangXuat_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn thoát khỏi phiên làm việc hiện nay hay không?", "Đăng xuất hệ thống", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                this.mainForm.IsWarningClosing = false;
                Application.Restart();
            }
        }
        
        void radMenuItem_QuanTriNguoiDung_Click(object sender, EventArgs e)
        {            
            radForm_SYS_QuanTriNguoiDung form = new radForm_SYS_QuanTriNguoiDung();
            form.MdiParent = this.mainForm;
            form.Show();
        }

        void radMenuItem_CauHinhKetNoi_Click(object sender, EventArgs e)
        {
            radForm_SYS_CauHinhKetNoi form = new radForm_SYS_CauHinhKetNoi();
            form.MdiParent = this.mainForm;
            form.Show();
        }

        void radMenuItem_PhanQuyenHeThong_Click(object sender, EventArgs e)
        {            
            radForm_SYS_PhanQuyenHeThong form = new radForm_SYS_PhanQuyenHeThong();
            form.MdiParent = this.mainForm;
            form.Show();
        }
        
        void radMenuItem_DanhMucPhongBan_Click(object sender, EventArgs e)
        {
            radForm_DanhMuc_PhongBan form = new radForm_DanhMuc_PhongBan();
            form.MdiParent = this.mainForm;
            form.Show();
        }

        void radMenuItem_DanhMucChiTieu_Click(object sender, EventArgs e)
        {
            radForm_DanhMuc_ChiTieu form = new radForm_DanhMuc_ChiTieu();
            form.MdiParent = this.mainForm;
            form.Show();
        }

        void radMenuItem_DanhMucLoaiChiTieu_Click(object sender, EventArgs e)
        {
            radForm_DanhMuc_LoaiChiTieu form = new radForm_DanhMuc_LoaiChiTieu();
            form.MdiParent = this.mainForm;
            form.Show();
        }

        void radMenuItem_DanhMucHeThong_Click(object sender, EventArgs e)
        {
            radForm_DanhMuc_DanhMucHeThong form = new radForm_DanhMuc_DanhMucHeThong();
            form.MdiParent = this.mainForm;
            form.Show();
        }
                
        private RadMenuItem CreateMenuItem(string text, string name, string imagePath)
        {            
            RadMenuItem radMenuItem = new RadMenuItem();
            radMenuItem.Name = name;
            radMenuItem.Text = text;
            //Stream imgStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("LIM.resources."+imagePath+".png");            
            radMenuItem.Image = Image.FromFile(path + imagePath); //new Bitmap(imgStream); //
            return radMenuItem;
        }
    }


}
